/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.quartz;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;

/**
 *
 * @author Administrator
 */
@Singleton
public class SchedulerManager {

    Scheduler scheduler;

    @Inject
    public SchedulerManager(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    /**
     * TODO: fix to use annotation, maybe add job dynamically at module
     *
     * @throws SchedulerException
     */
    public void start() throws SchedulerException {

        JobDetail mailJob = new JobDetail("batch", "email_group", CronAckEmailJob.class);
//        Trigger minute = TriggerUtils.makeMinutelyTrigger("deactivete_trigger");
        Trigger minute = TriggerUtils.makeDailyTrigger("deactivete_trigger", 00, 30);
        scheduler.scheduleJob(mailJob, minute);

        scheduler.start();
    }

    public void shutdown() throws SchedulerException {
        scheduler.shutdown();
    }
}
